package com.goldcup.common;

import com.alibaba.fastjson.JSONObject;

import java.util.Map;

public class ResponseData extends JSONObject {
    private static final int code=0;
    private static final String msg="success";

    public int getCode() {
        return this.getInteger("code");
    }

    public String getMsg() {
        return this.getString("msg");
    }

    public void setCode(int code){
        this.set("code",code);
    }

    public void setMsg(String msg){
        this.set("msg",msg);
    }

    public Long getTimestamp() {
        return this.getLong("timestamp");
    }

    public void setTimestamp(Long timestamp) {
        this.set("timestamp",timestamp);
    }

    public ResponseData set(String key, Object value, boolean force) {
        if (force || value != null) {
            super.put(key, value);
        }
        return this;
    }

    public ResponseData set(String key, Object value) {
        return this.set(key, value, true);
    }

    public ResponseData setAll(Map<? extends String, ? extends Object> m) {
        super.putAll(m);
        return this;
    }


    public ResponseData success(){
        this.setCode(0);
        this.setMsg("success");
        this.setTimestamp(System.currentTimeMillis());//当前时间的时间戳
        return this;
    }

    public ResponseData fail(){
        this.setCode(-1);
        this.setMsg("fail");
        this.setTimestamp(System.currentTimeMillis());//当前时间的时间戳
        return this;
    }
}
